<extend name="Public/layout" />

<block name="body">
    <div class="title">
        <h2>插件配置 [ {$data.title} ]</h2>
    </div>
    <form action="{:U('saveConfig')}" class="form" method="post">
        <empty name="custom_config">
            <foreach name="data['config']" item="form" key="key">
                <div class="form-group">
                    <present name="form.title">
                        <label class="item-label">
                            {$form.title|default=''}
                            <present name="form.tip">
                                <span class="check-tips">{$form.tip}</span>
                            </present>
                        </label>
                    </present>
                    <switch name="form.type">
                        <case value="text"><!-- 字符串 -->
                            <div class="controls">
                                <input type="text" class="form-control" name="config[{$key}]" class="text input-large" value="{$form.value}">
                            </div>
                        </case>
                        <case value="password"><!-- 密码 -->
                            <div class="controls">
                                <input type="password" class="form-control" name="config[{$key}]" class="text input-large" value="{$form.value}">
                            </div>
                        </case>
                        <case value="hidden"><!-- 隐藏 -->
                            <input type="hidden" class="form-control" name="config[{$key}]" value="{$form.value}">
                        </case>
                        <case value="radio"><!-- 单选按钮 -->
                            <div class="controls">
                                <foreach name="form.options" item="opt" key="opt_key">
                                    <label class="radio-inline" for="config[{$key}_{$opt_key}]">
                                        <input type="radio" id="config[{$key}_{$opt_key}]" name="config[{$key}]" value="{$opt_key}" <eq name="form.value" value="$opt_key"> checked</eq> class="checkbox"> {$opt}
                                    </label>
                                </foreach>
                            </div>
                        </case>
                        <case value="checkbox"><!-- 复选框 -->
                            <div class="controls">
                                <foreach name="form.options" item="opt" key="opt_k">
                                    <label class="checkbox-inline">
                                        <php>
                                            is_null($form["value"]) && $form["value"] = array();
                                        </php>
                                        <input type="checkbox" name="config[{$key}][]" value="{$opt_k}" <in name="opt_k" value="$form.value"> checked</in>>{$opt}
                                    </label>
                                </foreach>
                            </div>
                        </case>
                        <case value="select"><!-- 下拉框 -->
                            <div class="controls">
                                <select name="config[{$key}]" class="form-control">
                                    <foreach name="form.options" item="opt" key="opt_k">
                                        <option value="{$opt_k}" <eq name="form.value" value="$opt_k"> selected</eq>>{$opt}</option>
                                    </foreach>
                                </select>
                            </div>
                        </case>
                        <case value="textarea"><!-- 文本 -->
                            <div class="controls">
                                <textarea class="form-control" name="config[{$key}]">{$form.value}</textarea>
                            </div>
                        </case>
                        <case value="picture"><!-- 图片 -->
                            <div class="controls">
                                <div id="upload_{$key}"></div>
                                <div id="preview_{$key}">
                                    <input type="hidden" name="config[{$key}]" value="{$form.value}">
                                    <img style="margin-top:8px;max-height:60px;" src="{$form.value|get_cover}">
                                </div>
                                <link rel="stylesheet" type="text/css" href="__PUBLIC__/huploadify/huploadify.css">
                                <script type="text/javascript" src="__PUBLIC__/huploadify/huploadify.js" charset="utf-8"></script>
                                <script type="text/javascript">
                                    $('#upload_{$key}').Huploadify({
                                        uploader:'{:U("Upload/upload")}',
                                        fileTypeExts:'*.gif;*.jpg;*.jpeg;*.png;*.bmp',
                                        fileSizeLimit:{:C('UPLOAD_IMAGE_SIZE')}*1024,
                                        buttonText:'上 传 图 片',
                                        onUploadComplete:function(file, data){
                                            var data = $.parseJSON(data);
                                            $('#preview_{$key} img').attr('src', data.url);
                                            $('#preview_{$key} input').attr('value', data.id);
                                        }
                                    });
                                </script>
                            </div>
                        </case>
                        <case value="editor"><!-- 编辑器 -->
                            <textarea id="editor_{$key}" name="config[{$key}]" class="form-control">{$config.value}</textarea>
                            <link rel="stylesheet" type="text/css" href="__PUBLIC__/kindeditor/themes/default/default.css">
                            <script type="text/javascript" src="__PUBLIC__/kindeditor/kindeditor-min.js" charset="utf-8"></script>
                            <script type="text/javascript" src="__PUBLIC__/kindeditor/lang/zh_CN.js" charset="utf-8"></script>
                            <script type="text/javascript">
                                var editor_{$key};
                                KindEditor.ready(function(K) {
                                    editor_{$key} = K.create('#editor_{$key}', {
                                        allowFileManager : false,
                                        themesPath: K.basePath,
                                        height: '200px',
                                        resizeType: 1,
                                        pasteType : 2,
                                        urlType : 'absolute',
                                        items : [
                                            'fontname', 'fontsize', '|',
                                            'forecolor', 'hilitecolor', 'bold','italic', 'underline', 'removeformat','|',
                                            'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', '|',
                                            'emoticons', 'image', 'table', 'baidumap', 'link', 'unlink'
                                        ],
                                        fileManagerJson : '{:U("Upload/fileManager")}',
                                        uploadJson : '{:U("Upload/upload")}',
                                        remoteImgSaveUrl: '{:U("Upload/getImageBySrc")}',
                                        extraFileUploadParams: {
                                            session_id : '{:session_id()}'
                                        },
                                        afterBlur: function(){this.sync();}
                                    });
                                });
                            </script>
                        </case>
                        <case value="group">
                            <ul class="nav-pills nav">
                                <volist name="form.options" id="li">
                                    <li data-tab="tab{$i}" <eq name="i" value="1">class="active"</eq>><a href="#tab{$i}" data-toggle="tab">{$li.title}</a></li>
                                </volist>
                            </ul>
                            <div class="tab-content">
                                <volist name="form.options" id="tab">
                                    <div id="tab{$i}" class='tab-pane <eq name="i" value="1">active</eq> tab{$i}'>
                                        <foreach name="tab['options']" item="tab_form" key="tab_key">
                                            <div class="form-group">
                                                <label class="item-label">
                                                    {$tab_form.title|default=''}
                                                    <present name="tab_form.tip">
                                                        <span class="check-tips">{$tab_form.tip}</span>
                                                    </present>
                                                </label>
                                                <div class="controls">
                                                    <switch name="tab_form.type">
                                                        <case value="text"><!-- 字符串 -->
                                                            <div class="controls">
                                                                <input type="text" class="form-control" name="config[{$tab_key}]" class="text input-large" value="{$tab_form.value}">
                                                            </div>
                                                        </case>
                                                        <case value="password"><!-- 密码 -->
                                                            <div class="controls">
                                                                <input type="password" class="form-control" name="config[{$tab_key}]" class="text input-large" value="{$tab_form.value}">
                                                            </div>
                                                        </case>
                                                        <case value="hidden"><!-- 隐藏 -->
                                                            <input type="hidden" class="form-control" name="config[{$tab_key}]" value="{$tab_form.value}">
                                                        </case>
                                                        <case value="radio"><!-- 单选按钮 -->
                                                            <div class="controls">
                                                                <foreach name="tab_form.options" item="opt" tab_key="opt_tab_key">
                                                                    <label class="radio-inline" for="config[{$tab_key}_{$opt_tab_key}]">
                                                                        <input type="radio" id="config[{$tab_key}_{$opt_tab_key}]" name="config[{$tab_key}]" value="{$opt_tab_key}" <eq name="form.value" value="$opt_tab_key"> checked</eq> class="checkbox"> {$opt}
                                                                    </label>
                                                                </foreach>
                                                            </div>
                                                        </case>
                                                        <case value="checkbox"><!-- 复选框 -->
                                                            <div class="controls">
                                                                <foreach name="tab_form.options" item="opt" tab_key="opt_k">
                                                                    <label class="checkbox-inline">
                                                                        <php>
                                                                            is_null($tab_form["value"]) && $tab_form["value"] = array();
                                                                        </php>
                                                                        <input type="checkbox" name="config[{$tab_key}][]" value="{$opt_k}" <in name="opt_k" value="$tab_form.value"> checked</in>>{$opt}
                                                                    </label>
                                                                </foreach>
                                                            </div>
                                                        </case>
                                                        <case value="select"><!-- 下拉框 -->
                                                            <div class="controls">
                                                                <select name="config[{$tab_key}]" class="form-control">
                                                                    <foreach name="tab_form.options" item="tab_opt">
                                                                        <option value="{$key}" <eq name="tab_form.value" value="$key"> selected</eq>>{$tab_opt}</option>
                                                                    </foreach>
                                                                </select>
                                                            </div>
                                                        </case>
                                                        <case value="textarea"><!-- 文本 -->
                                                            <div class="controls">
                                                                <textarea class="form-control" name="config[{$tab_key}]">{$tab_form.value}</textarea>
                                                            </div>
                                                        </case>
                                                        <case value="picture"><!-- 图片 -->
                                                            <div class="controls">
                                                                <div id="upload_{$tab_key}"></div>
                                                                <div id="preview_{$tab_key}">
                                                                    <input type="hidden" name="config[{$tab_key}]" value="{$tab_form.value}">
                                                                    <img style="margin-top:8px;max-height:60px;" src="{$tab_form.value|get_cover}">
                                                                </div>
                                                                <link rel="stylesheet" type="text/css" href="__PUBLIC__/huploadify/huploadify.css">
                                                                <script type="text/javascript" src="__PUBLIC__/huploadify/huploadify.js" charset="utf-8"></script>
                                                                <script type="text/javascript">
                                                                    $('#upload_{$tab_key}').Huploadify({
                                                                        uploader:'{:U("Upload/upload")}',
                                                                        fileTypeExts:'*.gif;*.jpg;*.jpeg;*.png;*.bmp',
                                                                        fileSizeLimit:{:C('UPLOAD_IMAGE_SIZE')}*1024,
                                                                        buttonText:'上 传 图 片',
                                                                        onUploadComplete:function(file, data){
                                                                            var data = $.parseJSON(data);
                                                                            $('#preview_{$tab_key} img').attr('src', data.url);
                                                                            $('#preview_{$tab_key} input').attr('value', data.id);
                                                                        }
                                                                    });
                                                                </script>
                                                            </div>
                                                        </case>
                                                        <case value="editor"><!-- 编辑器 -->
                                                            <textarea id="editor_{$tab_key}" name="config[{$tab_key}]" class="form-control">{$config.value}</textarea>
                                                            <link rel="stylesheet" type="text/css" href="__PUBLIC__/kindeditor/themes/default/default.css">
                                                            <script type="text/javascript" src="__PUBLIC__/kindeditor/kindeditor-min.js" charset="utf-8"></script>
                                                            <script type="text/javascript" src="__PUBLIC__/kindeditor/lang/zh_CN.js" charset="utf-8"></script>
                                                            <script type="text/javascript">
                                                                var editor_{$tab_key};
                                                                KindEditor.ready(function(K) {
                                                                    editor_{$tab_key} = K.create('#editor_{$tab_key}', {
                                                                        allowFileManager : false,
                                                                        themesPath: K.basePath,
                                                                        height: '200px',
                                                                        resizeType: 1,
                                                                        pasteType : 2,
                                                                        urlType : 'absolute',
                                                                        items : [
                                                                            'fontname', 'fontsize', '|',
                                                                            'forecolor', 'hilitecolor', 'bold','italic', 'underline', 'removeformat','|',
                                                                            'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', '|',
                                                                            'emoticons', 'image', 'table', 'baidumap', 'link', 'unlink'
                                                                        ],
                                                                        fileManagerJson : '{:U("Upload/fileManager")}',
                                                                        uploadJson : '{:U("Upload/upload")}',
                                                                        remoteImgSaveUrl: '{:U("Upload/getImageBySrc")}',
                                                                        extraFileUploadParams: {
                                                                            session_id : '{:session_id()}'
                                                                        },
                                                                        afterBlur: function(){this.sync();}
                                                                    });
                                                                });
                                                            </script>
                                                        </case>
                                                    </switch>
                                                </div>
                                            </div>
                                        </foreach>
                                    </div>
                                </volist>
                            </div>
                        </case>
                    </switch>
                </div>
            </foreach>
        <else />
            <present name="custom_config">
                {$custom_config}
            </present>
        </empty>
        <input type="hidden" name="id" value="{:I('id')}" readonly>
        <button type="submit" class="btn btn-primary submit ajax-post" target-form="form">确 定</button>
        <button class="btn return" onclick="javascript:history.back(-1);return false;">返 回</button>
    </form>
</block>
